package site.luojie.core.filter;

import site.luojie.core.annotation.Component;
import site.luojie.core.annotation.Repository;
import site.luojie.core.annotation.Service;

import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;

/**
 * @Description: 自定义注解过滤
 * @Author jie.luo
 * @Create: 2020-05-06 00:22
 **/
public class ClassAnnotationFilter {

    public static Set<Class<?>> filter(Set<Class<?>> classes) {
        Set<Class<?>> customAnnotationClasses = new HashSet<>();
        if (null != classes) {
            for (Class<?> aClass : classes) {
                Annotation[] annotations = aClass.getAnnotations();
                if (null == annotations || annotations.length == 0) {
                    continue;
                }
                for (Annotation annotation : annotations) {
                    if (annotation.annotationType() == Component.class ||
                            annotation.annotationType() == Repository.class ||
                            annotation.annotationType() == Service.class) {
                        customAnnotationClasses.add(aClass);
                    }
                }
            }
        }
        return customAnnotationClasses;
    }


}
